package deatax;

import deatax.display.miniboard.SelectedTileRenderer;
import deatax.network.Client;
import deatax.state.LoseState;
import deatax.state.MainMenuState;
import deatax.state.PlacementState;
import deatax.state.RollState;
import deatax.state.TurnState;
import deatax.state.WaitState;
import deatax.state.WinState;
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.UIManager;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author pson
 */
public class Main {

    public static void main(String[] args) {

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception ex) {
        }
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                Main m = new Main();
                m.startGame();
            }
        });
    }

    public void startGame() {
        GameData data = new GameData();

        data.setFrame(new JFrame());
        data.getFrame().setGlassPane(ll);
        data.getFrame().getContentPane().setLayout(new BorderLayout());
        data.getFrame().setPreferredSize(new Dimension(800, 600));

        data.getFrame().setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        data.getFrame().pack();
        data.getFrame().setLocationRelativeTo(null);
        data.getFrame().setVisible(true);
        
        GameDataController gdc = new GameDataController(data);

        Client c = new Client(gdc);
        
        data.setState(new StateManager());

        data.getState().addState("MainMenu", new MainMenuState(data));
        data.setSelectedTileRenderer(new SelectedTileRenderer(data));
        data.getState().addState("Roll", new RollState(data));
        data.getState().addState("Turn", new TurnState(data));
        data.getState().addState("Wait", new WaitState(data));
        data.getState().addState("Placement", new PlacementState(data));
        data.getState().addState("Lose", new LoseState(data));
        data.getState().addState("Win", new WinState(data));

        data.getState().pushState("MainMenu");
    }

    public static LoadingLayer ll = new LoadingLayer();

    public static  void showLoading(){
        ll.start();
    }

    public static void stopLoading(){
        ll.stop();
    }
}
